﻿using Almacen.Data;
using Almacen.Data.Entities;
using Almacen.Data.Managers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;
using System.Data;
using System.Threading.Tasks;
using System.Web.Http.Description;

using System.Security.Claims;
using Almacen.Api.Models;

namespace Almacen.Api.Controllers
{
    [Authorize]
    [RoutePrefix("api/MeasureUnit")]
    //[EnableCors(origins: "120.0.0.1", headers: "*", methods: "*")]
    public class MeasureUnitController : ApiController
    {
        //private AlmacenDbContext db = new AlmacenDbContext();

        // GET api/MeasureUnit
        [Route("")]
        [Authorize(Roles = "User")]
        public IEnumerable<object> GetMeasureUnits()
        {
            /*return db.MeasureUnits.Select(c => new
            {
                Id = c.Id,
                Name = c.Name,
                Abbreviation = c.Abbreviation
            });
            
            
            
            
            IEnumerable<int> result = from value in Enumerable.Range(0, 2)
                                      select value;
            return result;
            */
            return MeasureUnitManager.getMeasureUnits().Select(c => new
            MeasureUnitModel()
            {
                
                Name = c.Name,
                Abbreviation = c.Abbreviation
            });

        }
    }
}
